var enrollAuthCodeInput = {
    inputAuthCode : "input[name=emailAuthCode]",
    submitButton : 'input[type=button]',
    inputAuthCodeOK : false
};

$(function() {
    $(enrollAuthCodeInput.inputAuthCode).focus();

    $(enrollAuthCodeInput.inputAuthCode).bind('input propertychange', function() {
        var reg = /^[a-zA-Z]{8}$/;
        var val = $(this).val();
        if (!reg.test(val)) {

            $("#enrollAuthCodeInput_flag").html("*验证码由8位英文字母组成");

            enrollAuthCodeInput.inputAuthCodeOK = false;

            $(this).css({
                border : '2px solid red'
            });
        } else {

            enrollAuthCodeInput.inputAuthCodeOK = true;

            $("#enrollAuthCodeInput_flag").html("&nbsp");
            $(this).css({
                border : '1px solid gray'
            });
        }
    });

    $(enrollAuthCodeInput.submitButton).click(function() {

        var reg = /^[a-zA-Z]{8}$/;
        var val = $(enrollAuthCodeInput.inputAuthCode).val();

        if (reg.test(val)) {
            enrollAuthCodeInput.inputAuthCodeOK = true;
        } else {
            enrollAuthCodeInput.inputAuthCodeOK = false;
        }

        if (!enrollAuthCodeInput.inputAuthCodeOK) {

            $("#enrollAuthCodeInput_flag").html("*验证码由8位英文字母组成");

            $(enrollAuthCodeInput.inputAuthCode).css({
                border : '2px solid red'
            });

            return;
        }
        $("#enrollAuthCodeInput_flag").html("&nbsp;");

        $(enrollAuthCodeInput.inputAuthCode).css({
            border : '1px solid gray'
        });

$("#enrollAuthCodeInputForm").submit();
    });

   /*
    $(document).keydown(function(e) {
           if (e.keyCode == 13) {
               $(enrollAuthCodeInput.submitButton).trigger('click');
           }
       });*/
   

});
